package com.qk.management.warmer;

import com.qk.management.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 缓存预热器：应用启动后(所有 Bean 初始化后)主动加载热点数据到缓存
 */
@Component
@Slf4j
public class CacheWarmerApplicationRunner implements ApplicationRunner {

    @Autowired
    private ReportService reportService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        try {
            log.info("开始缓存预热：调用 queryOverview() 方法");
            reportService.queryOverview();
            log.info("缓存预热完成：queryOverview() 数据已写入Redis");
        } catch (Exception e) {
            log.error("缓存预热失败：{}", e.getMessage());
        }
    }
}